package server;

import static constant.Constant.STR_CLIENT_CLOSED;
import static constant.Constant.STR_CLIENT_CONNECTED;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.SocketException;

import service.Service;

public class MultiServerThread extends Thread {
	private Socket socket = null;

	public MultiServerThread(Socket socket) {
		super("MultiServerThread");
		this.socket = socket;
	}

	public void run() {
		try {
			System.out.println(STR_CLIENT_CONNECTED);

			BufferedReader in = new BufferedReader(new InputStreamReader(
					socket.getInputStream()));
			DataOutputStream out = new DataOutputStream(
					socket.getOutputStream());

			try {
				new Service(in, out);
			} catch (SocketException e) {

			}
			in.close();
			out.close();
			socket.close();
			System.out.println(STR_CLIENT_CLOSED);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}